<template>
  <div class="product">
    <img :src="'/companys/' + randomSrc" @click="goto(item.pid)" alt="" />
    <div class="product_text">
      <h2 @click="goto(item.pid)">{{ item.pname }}</h2>
      <p>{{ item.promise }}</p>
      <div>
        <span>￥</span>
        <h1>{{ item.price }}</h1>
        <span>￥{{ item.price * 2 }}</span>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  computed: {
    randomSrc() {
      let picList = this.item.pics.split("=")
      //   console.log(picList)
      let index = Math.floor(Math.random() * picList.length)
      return picList[index]
    },
  },
  props: {
    item: {
      required: true,
    },
  },
  methods: {
    goto(pid) {
      this.$router.push("/pro_details?pid=" + pid)
    },
  },
}
</script>

<style lang="scss" scoped>
.product {
  display: flex;
  padding: 20px 0 35px 0;
  border-bottom: 1px solid #e8e8e8;
  > img {
    width: 40%;
    cursor: pointer;

    &:hover {
      opacity: 0.8;
    }
  }
  .product_text {
    display: flex;
    flex-direction: column;
    margin-left: 30px;
    justify-content: space-between;
    width: 100%;
    > h2 {
      width: 95%;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
      // display: inline-block;
      cursor: pointer;
    }
    > p {
      width: 90%;
      color: #666;
      flex: 1;
      // font-size: 16px;
      margin-top: 20px;
    }
    > div {
      color: #e4464b;
      display: flex;
      align-items: center;
      > span:first-child {
        display: block;
        padding-top: 5px;
        font-size: 20px;
      }
      > span:nth-child(3) {
        display: block;
        text-decoration: line-through;
        color: #999;
        padding-top: 5px;
        margin-left: 10px;
      }
    }
  }
}
</style>
